#include "EndState.h"

CEndState::CEndState()
{
	Init();
}

CEndState::~CEndState()
{
	if (m_pSound)
		delete m_pSound;
}

void CEndState::Init()
{
	m_pSound = CResourcesManager::GetInstance()->GetSound(ID_SOUND_END_THEME);
	m_bEnded = false;
	if (!m_pSound->IsSoundPlaying())
		m_pSound->Play();
}

void CEndState::Update(float deltaTime)
{

}

void CEndState::Render()
{
	if (m_bFinished)
		return;
	LPD3DXFONT* ppFont = CGraphic::GetInstance()->GetFontHandle();
	LPD3DXSPRITE ppSprite = CGraphic::GetInstance()->GetSpriteHandler();

	char info[50];
	RECT destSource;

	sprintf_s(info, "THANK YOU FOR PLAYING");
	destSource.left = 0;
	destSource.top = 145;
	destSource.bottom = 160;
	destSource.right = 512;

	(*ppFont)->DrawTextA(ppSprite, info, strlen(info), &destSource, DT_CENTER, 0xFFFFFFFF);
	if (CInput::GetInstance()->IsKeyDown(DIK_RETURN))
		m_bEnded = true;
}

void CEndState::End()
{
	m_bFinished = true;
	if (m_bEnded)
		exit(0);
}